/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2020年1月7日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.practice;

import java.util.Arrays;

/**
 * @Type A20200107_insertsort
 * @Desc
 * @author 52489
 * @date 2020年1月7日
 * @Version V1.0
 */
public class A20200107_insertsort {

    public static void main(String[] args) {
        int[] nums = { 3, 2, 1, 4, 8, 5, 9, 6 };
        insertsort(nums);
        System.out.println(Arrays.toString(nums));
    }

    /**
     * @param nums
     */
    private static void insertsort(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            int k = i;
            while (k > 0) {
                if (nums[k] < nums[k - 1]) {
                    int tmp = nums[k];
                    nums[k] = nums[k - 1];
                    nums[k - 1] = tmp;
                } else {
                    break;
                }
                k--;
            }
        }
    }

    private static void insertsort1(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            int k = i;
            int tmp = nums[i];
            while (k > 0) {
                if (tmp < nums[k - 1]) {
                    nums[k] = nums[k - 1];
                    k--;
                } else {
                    nums[k - 1] = tmp;
                    break;
                }
            }
        }
    }

}
